package com.blackcat.recode.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.blackcat.recode.common.result.AjaxResult;
import com.blackcat.recode.entity.Branch;
import com.blackcat.recode.entity.Customer;
import com.blackcat.recode.entity.Worker;
import com.blackcat.recode.dao.WorkerMapper;
import com.blackcat.recode.service.WorkerService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.blackcat.recode.utils.StringUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * <p> 运维人员表 服务实现类
 * @author blackcat 2024-09-13
 */
@Service
public class WorkerServiceImpl extends ServiceImpl<WorkerMapper, Worker> implements WorkerService {

    @Autowired
    private WorkerMapper workerMapper;

    @Override
    public AjaxResult getWorkerNameList() {
        QueryWrapper<Worker> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("id", "worker_name");
        return AjaxResult.success(workerMapper.selectList(queryWrapper));
    }

    @Override
    public AjaxResult getList(Integer pageNow, Integer pageSize, String workerName, String workerType) {
        QueryWrapper<Worker> queryWrapper = new QueryWrapper<>();
        if (StringUtils.isNotBlank(workerName)) {
            queryWrapper.like("worker_name", workerName);
        }
        if (StringUtils.isNotBlank(workerType)) {
            queryWrapper.eq("worker_type", workerType);
        }
        Page<Worker> page = new Page<>(pageNow, pageSize);
        Page<Worker> result = workerMapper.selectPage(page, queryWrapper);
        return AjaxResult.success(result);
    }

    @Override
    public AjaxResult edit(Worker worker) {
        if (worker.getId() == null) {
            workerMapper.insert(worker);
        }else {
            workerMapper.updateById(worker);
        }
        return AjaxResult.success();
    }
}
